package com.ruoyi.web.cp.domain.rm;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * @author xiesm
 * @Description: TODO
 * @date 2025-07-19 23:38
 */
@Data
@NoArgsConstructor
public class RmGame {
    private Long id;
    private String gameId;
    private Date date;
    private String league;
    private String teamA;
    private String teamB;
    private List<Detail> halfPlv;
    private List<Detail> allPlv;
    private List<ObDetail> obPlv;
    private List<Detail> goalTime5Plv;
    private List<Detail> goalTime10Plv;
    private String halfPlvJson;
    private String allPlvJson;
    private String goalTime5PlvJson;
    private String goalTime10PlvJson;
    private String obPlvJson;

    public RmGame(String gameId, Date date, String league, String teamA, String teamB) {
        this.gameId = gameId;
        this.date = date;
        this.league = league;
        this.teamA = teamA;
        this.teamB = teamB;
    }

    public List<Detail> allPlvFromJson() {
        if (this.allPlvJson == null || "null".equals(this.allPlvJson)) {
            return null;
        }
        return JSONArray.parseArray(this.allPlvJson, Detail.class);
    }

    public List<Detail> goalTime5PlvFromJson() {
        if (this.goalTime5PlvJson == null || "null".equals(this.goalTime5PlvJson)) {
            return null;
        }
        return JSONArray.parseArray(this.goalTime5PlvJson, Detail.class);
    }

    public ObDetail obPlvFromJson() {
        if (this.obPlvJson == null || "null".equals(this.obPlvJson)) {
            return null;
        }
        List<ObDetail> obDetails = JSONArray.parseArray(this.obPlvJson, ObDetail.class);
        return obDetails.get(0);
    }

    public String getHalfPlvJson() {
        if (this.halfPlv == null) {
            return null;
        }
        return JSON.toJSONString(this.halfPlv);
    }

    public String getAllPlvJson() {
        if (this.allPlv == null) {
            return null;
        }
        return JSON.toJSONString(this.allPlv);
    }

    public String getGoalTime5PlvJson() {
        if (this.goalTime5Plv == null) {
            return null;
        }
        return JSON.toJSONString(this.goalTime5Plv);
    }

    public String getGoalTime10PlvJson() {
        if (this.goalTime10Plv == null) {
            return null;
        }
        return JSON.toJSONString(this.goalTime10Plv);
    }

    public String getObPlvJson() {
        if (this.obPlv == null) {
            return null;
        }
        return JSON.toJSONString(this.obPlv);
    }

    public RmGame(String gameId, List<Detail> halfPlv, List<Detail> allPlv,
                  List<Detail> goalTime5Plv, List<Detail> goalTime10Plv) {
        this.gameId = gameId;
        this.halfPlv = halfPlv;
        this.allPlv = allPlv;
        this.goalTime5Plv = goalTime5Plv;
        this.goalTime10Plv = goalTime10Plv;
    }

    public RmGame(String gameId, List<ObDetail> obPlv) {
        this.gameId = gameId;
        this.obPlv = obPlv;
    }

    public String parseDateStr() {
        return DateUtil.format(this.date, "yyyy-MM-dd HH:mm");
    }

    @Data
    public static class Detail {
        private String score;
        private String plv;

        public Detail(String score, String plv) {
            this.score = score;
            this.plv = plv;
        }
    }
    @Data
    public static class ObDetail {
        //波胆00赔率
        private String bdan00_plv;
        //双进赔率
        private String double_plv;
        //大小球
        private String goal_desc;
        //半场大小球
        private String goal_half_desc;

        //独赢胜平负
        private String win_plv;
        private String draw_plv;
        private String lose_plv;

        //亚盘赔率
        private String asian_big_plv;
        private String asian_small_plv;
        private String asian_desc;

        //亚盘半场赔率
        private String asian_half_big_plv;
        private String asian_half_small_plv;
        private String asian_half_desc;

        //上下半场全胜-否
        private String sx_all_win_plv_teamA;
        private String sx_all_win_plv_teamB;

        //上半场零失球获胜-否
        private String s_ling_win_plv_teamA;
        private String s_ling_win_plv_teamB;

        //下半场零失球获胜-否
        private String x_ling_win_plv_teamA;
        private String x_ling_win_plv_teamB;

        //全场零失球获胜-否
        private String sx_ling_win_plv_teamA;
        private String sx_ling_win_plv_teamB;

        //全场零失球-否
        private String all_ling_plv_teamA;
        private String all_ling_plv_teamB;

        //上下半场均进球-是
        private String sx_have_goal_plv_t_teamA;
        private String sx_have_goal_plv_t_teamB;

        //上下半场均进球-否
        private String sx_have_goal_plv_teamA;
        private String sx_have_goal_plv_teamB;

        //全场反波胆
        private JSONObject qc_fbdan_plv;
        //上半场反波胆
        private JSONObject sbc_fbdan_plv;
        //下半场反波胆
        private JSONObject xbc_fbdan_plv;

    }
}
